package com.poposchool.project.mapper;

import com.poposchool.project.entity.Files;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author Wang Jie
 * @Date 2022/7/1 12:26
 * @Version 1.0
 */
public interface FileMapper {
    @Insert("insert into sys_file (id, name, type, size, url, is_delete, enable,md5)\n" +
            "values (#{id},#{fileName},#{type},#{size},#{url},#{isDelete},#{enable},#{md5});")
    void insert(Files files);


    @Select("SELECT * FROM sys_file where md5 = #{md5} limit 1")
    Files getFileMd5(String md5);

    List<Files> getPageFiles(@Param("pageNum") Integer pageNum,
                            @Param("pageSize") Integer pageSize,
                            @Param("name") String name
    );

    void batchDeleteFiles(@Param("ids") List<Integer> ids);

    @Select("select count(*) from sys_file")
    Integer getAllCount();

    @Delete("delete from sys_file where id = #{id}")
    void deleteFile(Integer id);

    @Update("update sys_file set enable = #{enable} where id = #{id}")
    void updateEnable(@Param("id") Integer id,@Param("enable") Boolean enable);

    @Select("select url from sys_file where enable = true")
    List<String> getEnableFile();
}
